package com.wpf.system.service.impl;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wpf.system.entity.EquipmentRent;
import com.wpf.system.entity.dto.BookRentBuySearchDTO;
import com.wpf.system.entity.vo.EquipmentChartVO;
import com.wpf.system.entity.vo.EquipmentRentVO;
import com.wpf.system.service.EquipmentRentService;
import com.wpf.system.mapper.EquipmentRentMapper;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
* @author ferna
* @description 针对表【equipment_rent(器材租赁表)】的数据库操作Service实现
* @createDate 2023-02-13 23:38:00
*/
@Service
public class EquipmentRentServiceImpl extends ServiceImpl<EquipmentRentMapper, EquipmentRent> implements EquipmentRentService{

    @Override
    public Boolean deleteEQRentById(Long id) {
        return Convert.toBool(this.baseMapper.deleteEQRentById(id));
    }

    @Override
    public List<EquipmentRentVO> getAllEquipmentRent(BookRentBuySearchDTO bookRentBuySearchDTO) {
        return this.baseMapper.getAllEquipmentRent(
                bookRentBuySearchDTO.getNo(),
                bookRentBuySearchDTO.getUid(),
                bookRentBuySearchDTO.getName(),
                bookRentBuySearchDTO.getNid(),
                bookRentBuySearchDTO.getUsername(),
                bookRentBuySearchDTO.getPhone(),
                bookRentBuySearchDTO.getStartTime(),
                bookRentBuySearchDTO.getEndTime(),
                bookRentBuySearchDTO.getPage(),
                bookRentBuySearchDTO.getPageSize()
        );
    }

    @Override
    public Long getOutTimeRent(Long uid) {
        LambdaQueryWrapper<EquipmentRent> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(EquipmentRent::getUid,uid);
        queryWrapper.eq(EquipmentRent::getStatus,6).or().eq(EquipmentRent::getStatus,9);
        return baseMapper.selectCount(queryWrapper);
    }

    @Override
    public List<EquipmentChartVO> getEquipmentRentChartData(String date) {
        Date d = DateUtil.parse(date);
        return this.baseMapper.getEquipmentRentChartData(
                DateUtil.beginOfDay(d).toString("yyyy-MM-dd HH:mm:ss"),
                DateUtil.endOfDay(d).toString("yyyy-MM-dd HH:mm:ss")
        );
    }
}




